package com.firefly.admin.tripartite.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.firefly.admin.common.annotations.annotation.OperationLog;
import com.firefly.admin.common.enums.OperationModuleEnum;
import com.firefly.admin.common.enums.OperationTypeEnum;
import com.firefly.admin.common.vo.Result;
import com.firefly.admin.tripartite.entity.FyTripartiteWechatOfficialAccount;
import com.firefly.admin.tripartite.service.FyTripartiteWechatOfficialAccountService;
import com.firefly.admin.tripartite.vo.WechatOfficialAccountQueryVo;
import com.firefly.admin.tripartite.vo.WechatOfficialAccountStatusUpdateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(tags = "第三方微信公众号接口API")
@RestController
@RequestMapping("/tripartite/wechat/official/account")
public class FyTripartiteWechatOfficialAccountController {

    @Autowired
    private FyTripartiteWechatOfficialAccountService fyTripartiteWechatOfficialAccountService;

    /**
     * 分页查询第三方微信公众号接口
     *
     * @param wechatOfficialAccountQueryVo 分页查询参数
     * @return 分页列表
     */
    @ApiOperation(value = "分页查询第三方微信公众号接口", notes = "分页查询第三方微信公众号接口", httpMethod = "GET")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:official:account')")
    @GetMapping("/list")
    public Result<Page<FyTripartiteWechatOfficialAccount>> getWechatOfficialAccountList(WechatOfficialAccountQueryVo wechatOfficialAccountQueryVo) {
        return fyTripartiteWechatOfficialAccountService.getWechatOfficialAccountList(wechatOfficialAccountQueryVo);
    }

    /**
     * 第三方微信公众号信息新增接口
     *
     * @param fyTripartiteWechatOfficialAccount 微信公众号信息
     * @return 操作结果
     */
    @ApiOperation(value = "第三方微信公众号信息新增接口", notes = "第三方微信公众号信息新增接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.TRIPARTITE_MANAGE, operateType = OperationTypeEnum.WECHAT_OFFICIAL_ACCOUNT, operateDesc = "第三方微信公众号新增")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:official:account:add')")
    @PostMapping("/add")
    public Result<FyTripartiteWechatOfficialAccount> add(@RequestBody FyTripartiteWechatOfficialAccount fyTripartiteWechatOfficialAccount) {
        return fyTripartiteWechatOfficialAccountService.add(fyTripartiteWechatOfficialAccount);
    }

    /**
     * 第三方微信公众号信息编辑接口
     *
     * @param fyTripartiteWechatOfficialAccount 微信公众号信息
     * @return 操作结果
     */
    @ApiOperation(value = "第三方微信公众号信息编辑接口", notes = "第三方微信公众号信息编辑接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.TRIPARTITE_MANAGE, operateType = OperationTypeEnum.WECHAT_OFFICIAL_ACCOUNT, operateDesc = "第三方微信公众号编辑")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:official:account:update')")
    @PostMapping("/update")
    public Result<FyTripartiteWechatOfficialAccount> update(@RequestBody FyTripartiteWechatOfficialAccount fyTripartiteWechatOfficialAccount) {
        return fyTripartiteWechatOfficialAccountService.update(fyTripartiteWechatOfficialAccount);
    }

    /**
     * 第三方微信公众号状态编辑接口
     *
     * @param wechatOfficialAccountStatusUpdateVo 状态信息
     * @return 操作结果
     */
    @ApiOperation(value = "第三方微信公众号状态编辑接口", notes = "第三方微信公众号状态编辑接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.TRIPARTITE_MANAGE, operateType = OperationTypeEnum.WECHAT_OFFICIAL_ACCOUNT, operateDesc = "第三方微信公众号修改状态")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:official:account:update:status')")
    @PostMapping("/update/status")
    public Result<FyTripartiteWechatOfficialAccount> updateStatus(@RequestBody WechatOfficialAccountStatusUpdateVo wechatOfficialAccountStatusUpdateVo) {
        return fyTripartiteWechatOfficialAccountService.updateStatus(wechatOfficialAccountStatusUpdateVo);
    }

    /**
     * 第三方微信公众号信息删除接口
     *
     * @param officialAccountId 微信公众号ID
     * @return 操作结果
     */
    @ApiOperation(value = "第三方微信公众号信息删除接口", notes = "第三方微信公众号信息删除接口", httpMethod = "POST")
    @OperationLog(module = OperationModuleEnum.TRIPARTITE_MANAGE, operateType = OperationTypeEnum.WECHAT_OFFICIAL_ACCOUNT, operateDesc = "第三方微信公众号删除")
    @PreAuthorize(value = "hasAuthority('tripartite:wechat:official:account:delete')")
    @PostMapping("/delete")
    public Result<String> delete(Long officialAccountId) {
        return fyTripartiteWechatOfficialAccountService.delete(officialAccountId);
    }

    /**
     * 第三方微信公众号APPID校验接口
     *
     * @param appId             微信公众号APPID
     * @param officialAccountId 微信公众号ID
     * @return 校验结果
     */
    @ApiOperation(value = "第三方微信公众号APPID校验接口", notes = "第三方微信公众号APPID校验接口", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appId", required = true, value = "微信公众号APPID", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "officialAccountId", required = true, value = "微信公众号ID", paramType = "query", dataType = "Long")
    })
    @GetMapping("/appid/check")
    public Result<String> appIdCheck(String appId, Long officialAccountId) {
        return fyTripartiteWechatOfficialAccountService.appIdCheck(appId, officialAccountId);
    }
}
